package com.stream.provider.controller;

import com.stream.provider.MySource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private Source source;

    @Autowired
    private MySource mySource;

    @GetMapping("/test")
    public String testSend(String msg){
        source.output().send(MessageBuilder.withPayload(msg).build());
        return "ok -> " + msg;
    }

    @GetMapping("/test1")
    public String testSend1(String msg){
        source.output().send(MessageBuilder.withPayload(msg).setHeader("test-header","my test").build());
        return "ok -> " + msg;
    }

    @GetMapping("/mytest")
    public String testSend2(String msg){
        mySource.output().send(MessageBuilder.withPayload(msg).build());
        return "ok -> " + msg;
    }
}
